﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using cwtrock.util;
using cwtrock.model;
using cwtrock.service.impl;

namespace cwtrock.view.sysmng
{
    public partial class bizhongAddFrm : Form
    {
        private SysCurrencyServiceImpl service =new SysCurrencyServiceImpl() ;
        private BizhongFrm parentFrm;
        private int id;

        public bizhongAddFrm(BizhongFrm parentFrm,int id)
        {
            InitializeComponent();
            this.parentFrm = parentFrm ;
            this.id = id;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string code = this.tbCode.Text;
            string name = this.tbName.Text;
            string rate = this.tbRate.Text;

            bool flagCode = SimpleTool.isEmpty(code);
            bool flagName = SimpleTool.isEmpty(name);
            if (flagCode)
            {
                MessageBox.Show("请填写币种代码", "提示信息", MessageBoxButtons.OK);
                return;
            }

            if (flagName)
            {
                MessageBox.Show("请填写币种名称", "提示信息", MessageBoxButtons.OK);
                return;
            }

            SysCurrency sc = new SysCurrency();
            if (id > 0)//修改当前记录
            {
                sc.CURRENCY_ID = id;
                sc.CURRENCY_CODE = code;
                sc.CURRENCY_NAME = name;
                sc.CURRENCY_RATE = rate;
                service.update(sc);
            }
            else
            {
                sc.CURRENCY_CODE = code;
                sc.CURRENCY_NAME = name;
                sc.CURRENCY_RATE = rate;
                service.save(sc);
            }
            parentFrm.refresh();
            this.Hide();
        }

        private void bizhongAddFrm_Load(object sender, EventArgs e)
        {
            SysCurrency c = this.service.getSysCurrency(id);
            this.tbCode.Text = c.CURRENCY_CODE;
            this.tbName.Text = c.CURRENCY_NAME;
            this.tbRate.Text = c.CURRENCY_RATE;

        }


    }
}
